const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')

// Generate pages object
const pagesObj = {};

const chromeName = ["popup", "options"];

chromeName.forEach(name => {
    pagesObj[name] = {
        entry: `src/${name}/index.js`,
        template: "public/index.html",
        filename: `${name}.html`
    };
});

//content_scripts
const content = {
    from: path.resolve("src/content/scp.js"),
    to: `${path.resolve("jszx")}/content/scp.js`
}

//logo
const logo = {
    from: path.resolve("src/assets/zwynt.png"),
    to: `${path.resolve("jszx")}/assets/zwynt.png`
}

const plugins =
    process.env.NODE_ENV === "production"
        ? [
            {
                from: path.resolve("src/manifest.production.json"),
                to: `${path.resolve("jszx")}/manifest.json`
            },
            {
                ...content
            },
            {
                ...logo
            }
        ]
        : [
            {
                from: path.resolve("src/manifest.development.json"),
                to: `${path.resolve("jszx")}/manifest.json`
            },
            {
                ...content
            },
            {
                ...logo
            }
        ];

module.exports = {
    outputDir:'jszx',
    pages: pagesObj,
    lintOnSave: false,
    configureWebpack: {
        plugins: [CopyWebpackPlugin(plugins),new NodePolyfillPlugin()]
    }
};
